<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>使用对象创建正则表达式</title>
</head>
<body>
    <div class="content">houdunren.com</div>
    <script>
        let hd = 'houdunren.com';
        // new RegExp(要查找的元素,全局)
        let reg = new RegExp('u','g');
        console.log(reg.test(hd));

        let a = 'u';
        // 查找的元素可以使用变量
        let reg1 = new RegExp(a,'g');
        console.log(reg1.test(hd));

        let con = prompt("请输入要检测的内容，支持正则表达式");
        let reg2 = new RegExp(con,'g');
        let div = document.querySelector('div');
        div.innerHTML = div.innerHTML.replace(reg2,search => {
            return `<span style="color:red;">${search}</span>`;
        })
    </script>
</body>
</html>